package cn.edu.ctbu.demo1.aspect;


import cn.edu.ctbu.demo1.core.RUtil;
import cn.edu.ctbu.demo1.exception.REnum;
import cn.edu.ctbu.demo1.exception.RException;
import cn.edu.ctbu.demo1.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 统一异常处理
 */
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if (e instanceof RException){
            RException rException = (RException) e;
            return RUtil.error(rException.getCode(),rException.getMessage());
        }

        return RUtil.error(REnum.UNKNOWN_ERR);
    }
}
